package com.bird.system.application.menu

import com.bird.system.application.menu.pl.*
import com.bird.system.domain.menu.MenuEntity
import com.bird.system.domain.menu.vo.MenuType
import com.bird.system.domain.menu.vo.UpdateMenuVO

/**
 * 添加菜单入参转实体
 */
fun AddMenuRequest.toEntity(): MenuEntity {
    return MenuEntity(
        menuName = this.menuName,
        parentId = this.parentId,
        treePath = this.treePath,
        routeName = this.routeName,
        routePath = this.routePath,
        component = this.component,
        keepAlive = this.keepAlive,
        hidden = this.hidden,
        alwaysShow = this.alwaysShow,
        redirect = this.redirect,
        sort = this.sort,
        menuType = MenuType.from(this.menuType),
        perm = this.perm,
        icon = this.icon
    )
}

/**
 * 修改菜单入参转更新值对象
 */
fun UpdateMenuRequest.toUpdateMenuVO(): UpdateMenuVO {
    return UpdateMenuVO(
        id = this.id,
        menuName = this.menuName,
        parentId = this.parentId,
        treePath = this.treePath,
        routeName = this.routeName,
        routePath = this.routePath,
        component = this.component,
        keepAlive = this.keepAlive,
        hidden = this.hidden,
        alwaysShow = this.alwaysShow,
        redirect = this.redirect,
        sort = this.sort,
        menuType = this.menuType?.let { MenuType.from(it) },
        perm = this.perm,
        icon = this.icon
    )
}

fun MenuEntity.toListMenuResponse(): ListMenuResponse {
    return ListMenuResponse(
        menuName = this.menuName,
        parentId = this.parentId,
        treePath = this.treePath,
        routeName = this.routeName,
        routePath = this.routePath,
        component = this.component,
        keepAlive = this.keepAlive == 1,
        hidden = this.hidden == 1,
        alwaysShow = this.alwaysShow == 1,
        redirect = this.redirect,
        sort = this.sort,
        menuType = this.menuType.value,
        perm = this.perm,
        icon = this.icon,
    )
}




